/*
 * @Author: xiehangyun 
 * @Date: 2025-05-16 10:49:46 
 * @Last Modified by: xiehangyun
 * @Last Modified time: 2025-05-16 10:52:51
 */

import { observable, configure } from "mobx";
import orderCompleteApi from "./OrderCompleteApi";
configure({ enforceActions: "never" });

const orderCompleteStore = observable({
    // 订单完成信息
    orderInfo: {
        id: '',
        status: '',
        amount: 0,
        paymentMethod: '',
        createTime: '',
        deliveryTime: '',
        items: [] as Array<{
            id: string;
            name: string;
            price: number;
            quantity: number;
            image: string;
        }>
    },

    // 评价信息
    rating: {
        score: 5,
        comment: ''
    },

    // 加载订单详情
    async loadOrderDetail(orderId: string) {
        const response = await orderCompleteApi.getOrderDetail(orderId);
        if (response.success) {
            this.orderInfo = response.data;
        }
        return response;
    },

    // 设置评价分数
    setRatingScore(score: number) {
        this.rating.score = score;
    },

    // 设置评价内容
    setRatingComment(comment: string) {
        this.rating.comment = comment;
    },

    // 提交评价
    async submitRating() {
        return await orderCompleteApi.rateOrder(
            this.orderInfo.id,
            this.rating.score,
            this.rating.comment
        );
    }
}, {}, { deep: false });

export default orderCompleteStore;